
#include "fig_ui_generalinfo.h"
#include "gen_game_state.h"
#include "fig_sounds.h"
#include "fighter.h"

#include "ui/ui_manager.h"
#include "gameflow/game_flow_manager.h"
#include "gameflow/ui_popup.h"
#include "gameflow/ui_state.h"
#include "font/font_manager.h"
#include "graphics/graphics.h"
#include "graphics/graphics_util.h"
#include "application/game_application.h"

#include "util/log.h"
#include "util/profiler.h"




using namespace gameflow;



FIGUIGeneralInfo::FIGUIGeneralInfo(const std::string& File):
			FIGUIPopupAnimator( File , ""),
			m_AlphaCounter(0.0f),
			m_pUIInfoTxt(NULL),
			m_Delay(0)
{
   
	if(m_pPopup)
	{
		m_pAnimateWidget = m_pPopup->GetWidget("BG");
		m_pPopup->SetWidgetFunctor("BG",UI_DELEGATE(FIGUIGeneralInfo, OnClickScreen));
		m_pPopup->SetWidgetFunctor("level_complete_box",UI_DELEGATE(FIGUIGeneralInfo, OnClickScreen));

		m_pUIInfoTxt = m_pPopup->GetWidget("info_text");
		

	}
	m_Type = ANIMATION_MSGPOPUP;
	
	
 
}


void	FIGUIGeneralInfo::Show()
{
	GENGameState::GetGame()->Pause();
	//audio::BassAudio::Instance().PauseAll();
	FIGUIPopupAnimator::Show();
}

void	FIGUIGeneralInfo::Hide()
{
	GENGameState::GetGame()->UnPause();
	//audio::BassAudio::Instance().RestartAll();
	FIGUIPopupAnimator::Hide();
}


void	FIGUIGeneralInfo::Tick(float dt)
{
	if(!m_pPopup)
		return;
	
	if(!m_pPopup->IsActive())
		return;

	if(m_Delay > 0)
	{
		m_Delay -= dt;
		if(m_Delay <= 0 )
		{
			Show();
		}
	}

	m_AlphaCounter.Tick(dt);
	if(m_AlphaCounter.IsReady())
		m_AlphaCounter.Reset();
	float Counter = m_AlphaCounter.GetCounter();
	float Alpha = 0;
	if(Counter < 0.5f)
		Alpha = Counter;
	else
		Alpha = 1.0f - Counter;
	

	Alpha += 0.7f;
	if(Alpha > 1.0f)
		Alpha = 1.0f;

	if(m_pUIInfoTxt)
		m_pUIInfoTxt->SetTextColor(Alpha,Alpha,Alpha,1.0f); 
	

	FIGUIPopupAnimator::Tick(dt);
}


void	FIGUIGeneralInfo::ShowThis(const std::string& Text,float Delay)
{
	m_Delay = Delay;
	if(m_pUIInfoTxt)
		m_pUIInfoTxt->SetTextA(Text);
	
}

void DELEGATE_CALL		FIGUIGeneralInfo::OnClickScreen(ui::UIWidget::WIDGET_EVENT Event, ui::UIWidget* pWidget)
{
		
	Hide();	
}
